pygame.math |
您所在的位置:网站首页 › pygame 3d桌面宠物 › pygame.math |
interpolates between two values by a weight.
lerp(a, b, weight) -> float
Linearly interpolates between a and b by weight using the formula a + (b-a) * weight. If weight is 0.5, lerp will return the value half-way between a and b. When a = 10 and b = 20, lerp(a, b, 0.5) will return 15. You can think of weight as the percentage of interpolation from a to b, 0.0 being 0% and 1.0 being 100%. lerp can be used for many things. You could rotate a sprite by a weight with angle = lerp(0, 360, weight). You could even scale an enemy's attack value based on the level you're playing: FINAL_LEVEL = 10 current_level = 2 attack = lerp(10, 50, current_level/MAX_LEVEL) # 18If you're on level 0, attack will be 10, if you're on level 10, attack will be 50. If you're on level 5, the result of current_level/MAX_LEVEL will be 0.5 which represents 50%, therefore attack will be 30, which is the midpoint of 10 and 50. Raises a ValueError if weight is outside the range of [0, 1]. New in pygame 2.1.3. |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |